home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Jotto ][ 1.2 / source / Jotto code ƒ / jotto meat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  2.0 KB  |  116 lines  |  [TEXT/MMCC]

  1. #include "program globals.h"
  2. #include "jotto meat.h"
  3. #include "jotto dictionary.h"
  4. #include "jotto environment.h"
  5. #include "util.h"
  6.  
  7. enum
  8. {
  9.     kGoDown=-1,
  10.     kGotIt,
  11.     kGoUp
  12. };
  13.  
  14. void NewWord(void)
  15. {
  16.     short            i;
  17.     
  18.     for (i=0; i<gNumLetters; i++)
  19.         gHumanWord[gNumTries][i]=' ';
  20.     gWhichChar=0x00;
  21. }
  22.  
  23. Boolean ValidWord(char *thisWord)
  24. {
  25.     if (InRealDictionary(thisWord))
  26.         return TRUE;
  27.     else
  28.         return (InCustomDictionary(thisWord));
  29. }
  30.  
  31. Boolean InCustomDictionary(char *thisWord)
  32. {
  33.     unsigned long    index;
  34.     char            temp[6];
  35.     short            found;
  36.     
  37.     if ((gNumLetters==5) ? (FiveLetterCustomOKQQ()) : (SixLetterCustomOKQQ()))
  38.     {
  39.         index=0L;
  40.         found=666;
  41.         while ((GetCustomWord(temp, index++)) && (found!=kGotIt))
  42.             found=DirectionalCompare(thisWord, temp);
  43.         
  44.         return (found==kGotIt);
  45.     }
  46.     else return FALSE;
  47. }
  48.  
  49. Boolean InRealDictionary(char *thisWord)
  50. {
  51.     unsigned long    index;
  52.     char            temp[6];
  53.     short            direction;
  54.     unsigned long    gap;
  55.     short            iter;
  56.     
  57.     index=gNumHumanWords[gNumLetters-5]/2;
  58.     gap=index;
  59.     iter=(gNumLetters==6) ? 14 : 13;
  60.     while (iter>0)
  61.     {
  62.         iter--;
  63.         if (gap%2)
  64.             gap=(gap>>1)+1;
  65.         else
  66.             gap=gap>>1;
  67.         GetHumanWord(temp, index);
  68.         direction=DirectionalCompare(thisWord, temp);
  69.         switch (direction)
  70.         {
  71.             case kGotIt:    return TRUE; break;
  72.             case kGoDown:    index-=gap; break;
  73.             case kGoUp:        index+=gap; break;
  74.         }
  75.         if (index<0)
  76.             index=0;
  77.         else if (index>=gNumHumanWords[gNumLetters-5])
  78.             index=gNumHumanWords[gNumLetters-5]-1;
  79.     }
  80.     
  81.     return FALSE;
  82. }
  83.  
  84. short DirectionalCompare(char *thisOne, char *thatOne)
  85. {
  86.     short            i;
  87.     
  88.     for (i=0; i<gNumLetters; i++)
  89.         if (thisOne[i]<thatOne[i])
  90.             return kGoDown;
  91.         else if (thisOne[i]>thatOne[i])
  92.             return kGoUp;
  93.  
  94.     return kGotIt;
  95. }
  96.  
  97. void CalculateNumRight(void)
  98. {
  99.     Boolean            used[6];
  100.     short            i,j;
  101.     
  102.     gNumRight[gNumTries]=0;
  103.     for (i=0; i<gNumLetters; i++)
  104.         used[i]=FALSE;
  105.     for (i=0; i<gNumLetters; i++)
  106.         for (j=0; j<gNumLetters; j++)
  107.         {
  108.             if ((gHumanWord[gNumTries][i]==gComputerWord[j]) && (!used[j]))
  109.             {
  110.                 gNumRight[gNumTries]++;
  111.                 used[j]=TRUE;
  112.                 j=gNumLetters;
  113.             }
  114.         }    
  115. }
  116.